import Vue from 'vue';
import VueRouter from 'vue-router';

import {
    Bar,
    Foo,
    LazyLoad,
    Parent,
    Child,
    Brother,
    Login
} from './pages';

Vue.use(VueRouter);

const routes = [
    {
        path:'/',
        redirect:'/foo'
    },
    {
        path:'/login',
        component:Login,
        name:'Login'
    },
    {
        path:'/bar',
        component:Bar,
        name:'Bar'
    },
    {
        path:'/lazyLoad',
        component:LazyLoad,
        name:'LazyLoad'
    },
    {
        path:'/parent',
        component:Parent,
        children:[
            {
                path:'child',
                component:Child,
            },
            {
                path:'brother',
                component:Brother,
            }
        ]
    }
];

export const router = new VueRouter({
   routes
});
router.beforeEach((to, from, next) => {
    Vue.prototype.$loading();
    next();
});
router.afterEach(route => {
    Vue.prototype.$loading.close();
});